﻿using NationalInstruments.DAQmx;
using Newtonsoft.Json;
using ScottPlot.Drawing.Colormaps;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Controls;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Enums;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Models;

namespace 低频天线阵列相控阵信号发生系统SmartFASK12.View
{
    public partial class USystem : UserControl
    {
        public USystem()
        {
            InitializeComponent();

            Init();
        }

        private void Init()
        {
            comboBox_PhysicalChannelName3.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AI));
            if (comboBox_PhysicalChannelName3.Items.Count > 0)
                comboBox_PhysicalChannelName3.SelectedIndex = 0;

            comboBox_PhysicalChannelName.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AO));
            comboBox_PhysicalChannelName2.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AO));
            if (comboBox_PhysicalChannelName.Items.Count > 0)
                comboBox_PhysicalChannelName.SelectedIndex = 0;
            if (comboBox_PhysicalChannelName2.Items.Count > 1)
                comboBox_PhysicalChannelName2.SelectedIndex = 1;

            comboBox_cjktype.SelectedIndex = (int)MPublic.ConfigModel.cjktype;

            if (MPublic.ConfigModel == null)
                return;

            comboBox_MinimumValue.Text = MPublic.ConfigModel.minimumValue.ToString();
            comboBox_MaximumValue.Text = MPublic.ConfigModel.maximumValue.ToString();
            comboBox_Rate.Text = MPublic.ConfigModel.rate.ToString();
            comboBox_signalFrequency.Text = MPublic.ConfigModel.signalFrequency.ToString();
            comboBox_carrierFrequency1.Text = MPublic.ConfigModel.carrierFrequency1.ToString();
            comboBox_carrierFrequency2.Text = MPublic.ConfigModel.carrierFrequency2.ToString();
            comboBox_range1.Text = MPublic.ConfigModel.range1.ToString();
            comboBox_range2.Text = MPublic.ConfigModel.range2.ToString();
            comboBox_benchmark1.Text = MPublic.ConfigModel.benchmark1.ToString();
            comboBox_benchmark2.Text = MPublic.ConfigModel.benchmark2.ToString();
            comboBox_phase1.Text = MPublic.ConfigModel.phase1.ToString();
            comboBox_phase2.Text = MPublic.ConfigModel.phase2.ToString();
            comboBox_dutyCycle.Text = Convert.ToDouble(MPublic.ConfigModel.dutyCycle * 100.0).ToString();
            comboBox_timeout.Text = MPublic.ConfigModel.timeout.ToString();
            comboBox_NumberSignals.Text = MPublic.ConfigModel.numbersignals.ToString();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Save_Click(object sender, EventArgs e)
        {
            MPublic.ConfigModel.physicalChannelName = comboBox_PhysicalChannelName.Text;
            MPublic.ConfigModel.physicalChannelName2 = comboBox_PhysicalChannelName2.Text;
            MPublic.ConfigModel.physicalChannelName3 = comboBox_PhysicalChannelName3.Text;
            MPublic.ConfigModel.maximumValue = Convert.ToDouble(comboBox_MaximumValue.Text);
            MPublic.ConfigModel.minimumValue = Convert.ToDouble(comboBox_MinimumValue.Text);
            MPublic.ConfigModel.rate = MConvert.Singleton().KToInt(comboBox_Rate.Text);
            MPublic.ConfigModel.cjktype = (CollectionCardTypeEnum)comboBox_cjktype.SelectedIndex;

            MPublic.ConfigModel.signalFrequency = MConvert.Singleton().KToInt(comboBox_signalFrequency.Text);
            MPublic.ConfigModel.carrierFrequency1 = MConvert.Singleton().KToInt(comboBox_carrierFrequency1.Text);
            MPublic.ConfigModel.carrierFrequency2 = MConvert.Singleton().KToInt(comboBox_carrierFrequency2.Text);
            MPublic.ConfigModel.range1 = Convert.ToDouble(comboBox_range1.Text);
            MPublic.ConfigModel.range2 = Convert.ToDouble(comboBox_range2.Text);
            MPublic.ConfigModel.benchmark1 = Convert.ToDouble(comboBox_benchmark1.Text);
            MPublic.ConfigModel.benchmark2 = Convert.ToDouble(comboBox_benchmark2.Text);
            MPublic.ConfigModel.phase1 = Convert.ToDouble(comboBox_phase1.Text);
            MPublic.ConfigModel.phase2 = Convert.ToDouble(comboBox_phase2.Text);
            MPublic.ConfigModel.dutyCycle = Convert.ToDouble(comboBox_dutyCycle.Text) / 100;
            MPublic.ConfigModel.timeout = Convert.ToInt16(comboBox_timeout.Text);

            MPublic.ConfigModel.numbersignals = Convert.ToInt32(comboBox_NumberSignals.Text);

            MPublic.ConfigModel = MPublic.ConfigModel;

            MessageBox.Show("保存成功！", "提示");
        }
    }
}
